/* 人才模块　*/
/* by Simon 20150515 */

//获取职位子分类
function getSubPosition(parent_no,curr_no){
    if(parent_no=='') return false;
    var selected = '';
    $.ajax({
        type:"get",
        url:"/?m=hchhr&c=index&a=load_position&parent_no="+parent_no,
        data:'',
        dataType:"json",
        success:function(data){
            $.each(data,function(index,val){
                if(curr_no!='' && val.position_no==curr_no){
                    selected = 'selected';
                }
                else{
                    selected = '';
                }
                $("select[name='position2']").append("<option value='"+val.position_no+"' "+selected+">"+val.position_name+"</option>");
           });
        }
    });
}

//获取行业子分类
function getSubIndustry(parent_no,curr_no){
    if(parent_no=='') return false;
    var selected = '';
    $.ajax({
        type:"get",
        url:"/?m=hchhr&c=index&a=load_industry&parent_no="+parent_no,
        data:'',
        dataType:"json",
        success:function(data){
                $.each(data,function(index,val){
                    if(curr_no!='' && val.industry_no==curr_no){
                        selected = 'selected';
                    }
                    else{
                        selected = '';
                    }
                    $("select[name='industry2']").append("<option value='"+val.industry_no+"' "+selected+">"+val.industry_name+"</option>");
        });
        }
    });
}

//获取城市
function getCity(parent_no,curr_no){
    if(parent_no=='') return false;
    var selected = '';
    $.ajax({
        type:"get",
        url:"/?m=hchhr&c=position&a=load_city&parent_no="+parent_no,
        data:'',
        dataType:"json",
        success:function(data){
            $.each(data,function(index,val){
                if(curr_no!='' && val.area_no==curr_no){
                    selected = 'selected';
                }
                else{
                    selected = '';
                }
                $("select[name='city']").append("<option value='"+val.area_no+"' "+selected+">"+val.area_name+"</option>");
            });
        }
    });
}

//发布职位 表单验证
function checkPosition(the)
{
    if(the.job_name.value==''){
        alert('请输入招聘职位名称！');
        the.job_name.focus();
        return false;
    }

    if(the.position.value==''){
        alert('请选择职位大类！');
        the.position.focus();
        return false;
    }
    if(the.position2.value==''){
        alert('请选择职位小类！');
        the.position2.focus();
        return false;
    }

    if(the.industry.value==''){
        alert('请选择行业大类！');
        the.industry.focus();
        return false;
    }
    if(the.industry2.value==''){
        alert('请选择行业小类！');
        the.industry2.focus();
        return false;
    }
    if(the.province.value==''){
        alert('请选择省份！');
        the.province.focus();
        return false;
    }
    if(the.city.value==''){
        alert('请选择城市！');
        the.city.focus();
        return false;
    }
    if(the.job_money.value==''){
        alert('请选择职位月薪！');
        the.job_money.focus();
        return false;
    }
    if(the.job_nature.value==''){
        alert('请选择工作性质！');
        the.job_nature.focus();
        return false;
    }
    if(the.job_desc.value==''){
        alert('请输入职位描述！');
        the.job_desc.focus();
        return false;
    }
    if(the.job_num.value==''){
        alert('请输入招聘人数！');
        the.job_num.focus();
        return false;
    }
    if(the.job_endtime.value==''){
        alert('请选择截止日期！');
        the.job_endtime.focus();
        return false;
    }
    if(the.job_linkman.value==''){
        alert('请输入联系人姓名！');
        the.job_linkman.focus();
        return false;
    }
    if(the.job_tel.value==''){
        alert('请输入联系电话！');
        the.job_tel.focus();
        return false;
    }
	data  ="job_name="+encodeURIComponent($.trim(the.job_name.value));
	data +="&jobid="+$.trim(the.jobid.value);
    data +="&position="+$.trim(the.position.value);
    data +="&position2="+the.position2.value;
    data +="&industry="+the.industry.value;
    data +="&industry2="+the.industry2.value;
    data +="&province="+the.province.value;
    data +="&city="+the.city.value;
    data +="&job_money="+encodeURIComponent($.trim(the.job_money.value));
    data +="&job_nature="+encodeURIComponent($.trim(the.job_nature.value));
    data +="&job_desc="+encodeURIComponent($.trim(the.job_desc.value));
    data +="&job_age="+the.job_age.value;
    data +="&job_edu="+the.job_edu.value;
    data +="&job_num="+the.job_num.value;
    data +="&job_welfare="+encodeURIComponent($.trim(the.job_welfare.value));
    data +="&job_endtime="+encodeURIComponent($.trim(the.job_endtime.value));
    data +="&job_linkman="+encodeURIComponent($.trim(the.job_linkman.value));
    data +="&job_tel="+encodeURIComponent($.trim(the.job_tel.value));
    data +="&job_email="+encodeURIComponent($.trim(the.job_email.value));

	data +="&position_name="+the.position.options[the.position.selectedIndex].text;
	data +="&position2_name="+the.position2.options[the.position2.selectedIndex].text;
	data +="&industry_name="+the.industry.options[the.industry.selectedIndex].text;
	data +="&industry2_name="+the.industry2.options[the.industry2.selectedIndex].text;
	data +="&province_name="+the.province.options[the.province.selectedIndex].text;
	data +="&city_name="+the.city.options[the.city.selectedIndex].text;

    var url,data,go_url;
    url = "/?m=hchhr&c=position&a=save";
    go_url = "/?m=hchhr&c=position&a=publish";
    $.ajax({
        type:"post",
        cache:false,
        url:url,
        data:data,
        error:function(){alert('Server error！');},
        success:function(_)
        {
            var act=_.substring(0,1);
            var info=_.substring(1);
            switch(act)
            {
                case "0":
                    alert(info);
                    break;
                case "1":
                    alert(info);
                    setTimeout("location.href='"+go_url+"'",1000);
                    break;
                default:
                    document.write(_);
                    break;
            }
        }
    });
    return false;
}
//选择日期
function selectdate(lang)
{
    var date = new Date(Date());
    date = date.valueOf();
    //date = date + 1*24*60*60*1000; //明天的日期
    date = new Date(date);
    var tomorrow = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    if(lang=='en')
    {
        WdatePicker({isShowClear:false,readOnly:true,skin:'ext',doubleCalendar:false,dateFmt:'yyyy-MM-dd',minDate:tomorrow,lang:'en'});
    }
    else
    {
        WdatePicker({isShowClear:false,readOnly:true,skin:'ext',doubleCalendar:false,dateFmt:'yyyy-MM-dd',minDate:tomorrow});
    }
}